package com.itr.kbm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itr.kbm.dao.UserDao;
import com.itr.kbm.model.User;


//@Service("userDetailsService") 
public class UserDetailsServiceImpl implements UserDetailsService  {	    
	
  //@Autowired 
  private UserDao userDao;
  //@Autowired 
  private Assembler assembler;

  @Transactional(readOnly = true)
  public UserDetails loadUserByUsername(String username)
      throws UsernameNotFoundException, DataAccessException {

	System.out.println("searching for user : " + username);  
    
    User userEntity = userDao.login(username);            
    
    System.out.println("User Name = " + userEntity.getUsername());
    System.out.println("User found = " + userEntity.toString());
    
    return assembler.buildUserFromUserEntity(userEntity);
  }
  
}